//
// Created by liuzhen on 8/8/18.
//

#include "firstNodeCmd.h"
#include "firstNode.h"

MStatus firstNodeCmd::doIt(const MArgList &args)
{
    MStatus status;
    return redoIt();

}

MStatus firstNodeCmd::redoIt()
{
    MStatus status;

    MSelectionList sel;
    MGlobal::getActiveSelectionList( sel );
    MItSelectionList selIter( sel );
    MFnTransform transFn;
    for ( ; !selIter.isDone(); selIter.next()){
        MDagPath path;
        selIter.getDagPath(path);

        transFn.setObject( path );
        MPlug transPlug = transFn.findPlug( "translateY" );
        MGlobal::displayInfo(transPlug.name());
        MFnDependencyNode nodeFn;
        MObject myNode = nodeFn.create(firstNode::id);
        MPlug nodePlug = nodeFn.findPlug( "output" );
        MGlobal::displayInfo(nodePlug.name());
        mod.connect(nodePlug, transPlug);
        myNodeArray.append(myNode);

    }
    mod.doIt();
    return MS::kSuccess;

}

MStatus  firstNodeCmd::undoIt() {
    MStatus status;
    for (unsigned int i=0; i < myNodeArray.length(); i++){
        MGlobal::deleteNode(myNodeArray[i]);
    }
    return MS::kSuccess;
}